thin.define(function(exports) {
	var banner = document.getElementById('layout-banner'),
		li_arr = banner.getElementsByTagName('li'),
		img_arr = banner.getElementsByTagName('img'),
		em_arr = [],
		length = li_arr.length,
		maxIndex = length - 1,
		index = 0,
		nowIndex = index,
		time = 3200,
		timeout;

	var span = document.createElement('span');
	span.className = 'layout-banner-menu';
	for(var i = 0; i < li_arr.length; i++) {
		var em = document.createElement('em');
		em.setAttribute('data-index', i);
		em.onclick = function(e) {
			tool.stopPropagation(e);
			var _index = this.getAttribute('data-index');
			selectBanner(_index);
		};
		em_arr.push(em);
		span.appendChild(em);
	}
	banner.parentNode.insertBefore(span, banner.nextSibling);

	function loopBanner(_index) {
		clearTimeout(timeout);
		_index && (index = _index);
		var li = li_arr[index],
			em = em_arr[index];
		$(li).stop(true).fadeIn(320);
		em.className = 'active';
		var prev = _index ? nowIndex : (index <= 0 ? maxIndex : index - 1),
			prev_li = li_arr[prev],
			prev_em = em_arr[prev];
		$(prev_li).stop(true).fadeOut(320);
		prev_em.className = '';
		nowIndex = index;
		index = index >= maxIndex ? 0 : ++index;
		timeout = setTimeout(loopBanner, time);
	}

	function selectBanner(_index) {
		if(_index == nowIndex) return;
		loopBanner(_index);
	}

	var banner = function(_t) {
		_t && (time = _t);
		loopBanner();
	}

	exports('banner', banner);
});